Skip to content

simple-linked-list: sync missing test cases and add peek/toList#3146

Open
AdityaPudasaini wants to merge 2 commits into
exercism:mainfrom
AdityaPudasaini:simple-linked-list-sync-tests
Open

simple-linked-list: sync missing test cases and add peek/toList#3146
AdityaPudasaini wants to merge 2 commits into
exercism:mainfrom
AdityaPudasaini:simple-linked-list-sync-tests

Conversation

@AdityaPudasaini

@AdityaPudasaini AdityaPudasaini commented Jun 24, 2026

Copy link
Copy Markdown

Pull Request

Syncs the simple-linked-list exercise with the latest problem specifications.

Changes:

  • Added 29 missing test cases via configlet sync
  • Added peek() method to stub and reference solution
  • Added toList() method to stub and reference solution
  • Updated .meta/tests.toml with all new test UUIDs

All 34 tests pass locally.

Fixes #2959


Reviewer Resources:

Track Policies

@github-actions

Copy link
Copy Markdown
Contributor

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

@AdityaPudasaini

Copy link
Copy Markdown
Author

These changes do affect test outcomes as they add 29 missing test cases to sync with the latest problem specifications. Happy to add [no important files changed] to the commit message if the maintainers prefer, but I believe re-running student tests is appropriate here.

@kahgoh kahgoh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AdityaPudasaini, thanks for raising the PR to update the tests.

These changes do affect test outcomes as they add 29 missing test cases to sync with the latest problem specifications.

Actually, some of the tests have already been written - the tests.toml just haven't been synced so configlet couldn't see them. As a result I noticed some of the tests have now been duplicated (this is mentioned in one of comments below).

Happy to add [no important files changed] to the commit message if the maintainers prefer, but I believe re-running student tests is appropriate here.

No need to add this comment - we'll add it at merge time if we think it is appropriate. But you are also right - adding new tests and new methods is going to break all the existing solutions.

@DisplayName("count -> Empty list has length of zero")
public void countEmptyListHasLengthOfZero() {
SimpleLinkedList<Integer> list = new SimpleLinkedList<>();
assertThat(list.size()).isEqualTo(0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is the same as aNewTestIsEmpty. In fact, I noticed there are more tests that have also been duplicated (e.g. popFromEmptyListIsAnError is a copy of popOnEmptyListWillThrow). Could you please remove the duplicates? I suspect you'll be able to remove the "old" version of the tests.

Comment on lines +22 to 27
List<T> toList() {
throw new UnsupportedOperationException("Please implement the SimpleLinkedList.toList() method.");
}
T[] asArray(Class<T> clazz) {
throw new UnsupportedOperationException("Please implement the SimpleLinkedList.asArray() method.");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a bit strange to have both these methods for this exercise. I think we should choose one to go with and remove the tests for the other. If we go with asArray then the toList tests can use asArray instead.

Comment on lines +256 to +312
@Disabled("Remove to run test")
@Test
@DisplayName("toList LIFO -> Empty linked list to list is empty")
public void toListLifoEmptyLinkedListToListIsEmpty() {
SimpleLinkedList<Integer> list = new SimpleLinkedList<>();
assertThat(list.toList()).isEmpty();
}

@Disabled("Remove to run test")
@Test
@DisplayName("toList LIFO -> To list with multiple values")
public void toListLifoToListWithMultipleValues() {
SimpleLinkedList<Integer> list = new SimpleLinkedList<>(new Integer[]{1, 2, 3});
assertThat(list.toList()).containsExactly(1, 2, 3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("toList LIFO -> To list after a pop")
public void toListLifoToListAfterAPop() {
SimpleLinkedList<Integer> list = new SimpleLinkedList<>();
list.push(1);
list.push(2);
list.push(3);
assertThat(list.pop()).isEqualTo(3);
list.push(4);
assertThat(list.toList()).containsExactly(4, 2, 1);
}

@Disabled("Remove to run test")
@Test
@DisplayName("toList FIFO -> Empty linked list to list is empty")
public void toListFifoEmptyLinkedListToListIsEmpty() {
SimpleLinkedList<Integer> list = new SimpleLinkedList<>();
assertThat(list.toList()).isEmpty();
}

@Disabled("Remove to run test")
@Test
@DisplayName("toList FIFO -> To list with multiple values")
public void toListFifoToListWithMultipleValues() {
SimpleLinkedList<Integer> list = new SimpleLinkedList<>(new Integer[]{1, 2, 3});
assertThat(list.toList()).containsExactly(1, 2, 3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("toList FIFO -> To list after a pop")
public void toListFifoToListAfterAPop() {
SimpleLinkedList<Integer> list = new SimpleLinkedList<>();
list.push(1);
list.push(2);
list.push(3);
assertThat(list.pop()).isEqualTo(3);
list.push(4);
assertThat(list.toList()).containsExactly(4, 2, 1);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really make sense to have both FIFO and LIFO tests. It should have just the FIFO set or the LIFO set. This is mentioned in the comments at the top of the canonical-data 👇🏻:

"The linked list implements a LIFO. A pop retrieves the last-in value. ",
"As such, the toList operation can be thought as being build using pops, ",
"which means list([1, 2, 3]).toList() would return [3, 2, 1]. ",
"Conversely, the toList is more intuitive to some if it returns data matching how the list was build, ",
"so list([1, 2, 3]).toList() would return [1, 2, 3].",
"",
"To preserve both options, this data has two test groups: toList LIFO and toList FIFO.",
"The tests in these groups are mutually exclusive.",

Also, the expectations don't match the canonical data in some of your tests either. For example, the expectation for toListLifoToListWithMultipleValues should be [3, 2, 1], not [1, 2, 3], and for toListFifoToListAfterAPop, it should be [1, 2, 4], not [4, 2, 1].

Anyway, to fix this:

  1. Decide whether to use the LIFO set or FIFO set. I'd prefer using the set that aligns best with the existing asArray method. I think that is the LIFO set.
  2. In tests.toml mark the removed tests as skipped. To do this, you can add include = false. See line 29 in the one for hamming for an example.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed review @kahgoh! I'll remove the duplicate tests, go with the LIFO set, mark the FIFO tests as include = false in tests.toml, and fix the expectations. I'll push the changes shortly.

@AdityaPudasaini AdityaPudasaini Jun 25, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kahgoh , I've addressed all the feedback:

Removed duplicate tests (old aNewListIsEmpty, popOnEmptyListWillThrow, etc.)
Kept only the LIFO set and marked FIFO tests as include = false in tests.toml
Fixed the toList expectations to match canonical data
All 27 tests pass locally

@kahgoh kahgoh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that is looking better! Some of the expectations are still different to what is in the canonical data though (see comments below).

Also, did you see my comment about having both toList and asArray? What were your thoughts about having just one or the other?

@DisplayName("pop -> Can pop from non-empty list")
public void canPopFromNonEmptyList() {
SimpleLinkedList<Integer> list = new SimpleLinkedList<>(new Integer[]{1, 2});
assertThat(list.pop()).isEqualTo(1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be equal to 2?

SimpleLinkedList<Integer> list = new SimpleLinkedList<>(new Integer[]{1, 2});
assertThat(list.pop()).isEqualTo(1);
assertThat(list.pop()).isEqualTo(2);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be equal to 2 then 1?

assertThat(list.pop()).isEqualTo(9);
assertThat(list.pop()).isEqualTo(1);
assertThat(list.size()).isEqualTo(1);
assertThat(list.pop()).isEqualTo(2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to other comment, should the expectation for pop be 2 then 1?

Comment on lines +233 to +235
assertThat(list.pop()).isEqualTo(1);
assertThat(list.pop()).isEqualTo(2);
assertThat(list.pop()).isEqualTo(3);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the the results from pop be 3, 2 then 1?

Comment on lines +221 to +223
assertThat(list.pop()).isEqualTo(3);
assertThat(list.pop()).isEqualTo(2);
assertThat(list.pop()).isEqualTo(1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the result from pop be 1, 2 then 3?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kahgoh, thanks for the continued feedback! I want to make sure I understand correctly before making changes.
Regarding canPopFromNonEmptyList — the current constructor pushes elements in reverse order so that 1 ends up at the head, making pop() return 1 first. Should the constructor instead push in forward order so that the last element 2 is at the head?
Also regarding having both toList and asArray — I'd suggest keeping toList and removing asArray tests since toList returns a List which is more idiomatic modern Java. Happy to go with whatever you prefer though.
Please let me know and I'll update accordingly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚨 configlet sync --test found unsynced tests

2 participants